package com.putong35.common.account.data.http;

import android.text.TextUtils;

import com.putong35.common.account.Account;
import com.putong35.common.app.BaseApplication;
import com.putong35.common.httprequest.OnFailureListener;
import com.putong35.common.httprequest.OnSuccessListener;
import com.putong35.common.httprequest.retrofit.HttpCommonCallback;

import java.util.HashMap;

import retrofit2.Call;
import retrofit2.Retrofit;

public class AccountApiHelper {
    public static final String SMS_TYPE_REGISTER = "register";
    public static final String SMS_TYPE_LOGIN = "login";
    public static final String TAG = "HttpCommon";



    public static void register(String mobile, String pwd, String captcha, String inviteCode, OnSuccessListener<Account> successListener, OnFailureListener failureListener) {
        Retrofit retrofit = BaseApplication.retrofit();
        AccountApi request = retrofit.create(AccountApi.class);

        HashMap<String, String> map = new HashMap<>();
        map.put("mobile", mobile);
        map.put("password", pwd);
        map.put("loginCode", captcha);
        map.put("recommandNumber", "");

        Call<Account> call = request.register(map);
        HttpCommonCallback<Account> callback = new HttpCommonCallback<>(successListener, failureListener);
        call.enqueue(callback);
    }


    public static void login(String mobile, String pwd, String captcha, OnSuccessListener<Account> successListener, OnFailureListener failureListener) {
        Retrofit retrofit = BaseApplication.retrofit();
        AccountApi request = retrofit.create(AccountApi.class);

        HashMap<String, String> map = new HashMap<>();
        map.put("mobile", mobile);
        map.put("password", pwd);
        map.put("loginCode", captcha);

        Call<Account> call = request.login(map);
        HttpCommonCallback<Account> callback = new HttpCommonCallback<>(successListener, failureListener);
        call.enqueue(callback);
    }


    public static void changePwd(String mobile, String pwd, String captcha, OnSuccessListener<String> successListener, OnFailureListener failureListener) {
        Retrofit retrofit = BaseApplication.retrofit();
        AccountApi request = retrofit.create(AccountApi.class);

        HashMap<String, String> map = new HashMap<>();
        map.put("mobile", mobile);
        map.put("password", pwd);
        map.put("loginCode", captcha);

        Call<String> call = request.changePwd(map);
        HttpCommonCallback<String> callback = new HttpCommonCallback<>(successListener, failureListener);
        call.enqueue(callback);
    }


    /**
     * 修改用户信息
     *
     * @param nickName
     * @param sex             性别传整数， 没有值就传-1
     * @param headImg
     * @param successListener
     * @param failureListener
     */
    public static void edit(String nickName, int sex, String headImg, OnSuccessListener<Account> successListener, OnFailureListener failureListener) {
        Retrofit retrofit = BaseApplication.retrofit();
        AccountApi request = retrofit.create(AccountApi.class);

        HashMap<String, String> map = new HashMap<>();
        if (!TextUtils.isEmpty(nickName)) {

            map.put("nickName", nickName);
        }
        if (sex >= 0) {
            map.put("sex", "" + sex);
        }
        if (!TextUtils.isEmpty(headImg)) {
            map.put("headImg", headImg);
        }

        Call<Account> call = request.edit(map);
        HttpCommonCallback<Account> callback = new HttpCommonCallback<>(successListener, failureListener);
        call.enqueue(callback);
    }




}
